`
https://leetcode.cn/problems/partition-list/
`

/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @param {number} x
 * @return {ListNode}
 */
var partition = function (head, x) {
  // 创建两个链表，一个存放小于x的节点，一个存放大于等于x的节点
  // 最后将两个链表连接起来返回即可
  if (!head) return null
  const dummy1 = new ListNode()
  const dummy2 = new ListNode()
  let lessLink = dummy1
  let moreLink = dummy2
  let cur = head
  while (cur) {
    if (cur.val >= x) {
      moreLink.next = new ListNode(cur.val)
      moreLink = moreLink.next
    } else {
      lessLink.next = new ListNode(cur.val)
      lessLink = lessLink.next
    }
    cur = cur.next
  }
  if (moreLink === dummy2) return dummy1.next
  lessLink.next = dummy2.next
  return dummy1.next
};